#!/bin/sh -
PROGRAM=monitor.sh
JAVA_OPT="-server -Xms16M -Xmx32M"
COMMAND="java $JAVA_OPT -cp conf:lib/*:monitor-web-1.0.jar cn.com.infcn.monitor.server.MonitorServer"

fstart() {
	echo "start monitor in foreground..."
	${COMMAND}
	echo "shutdown done"
}

start() {
	echo "start monitor ..."
	${COMMAND} > /dev/null 2>&1 &
	if [ $? -eq 0 ]
	then
		echo $! > monitor.pid
		echo "done"
	else
		echo "start monitor failed"
	fi
}

stop() {
	if [ -f monitor.pid ]
	then
		cat monitor.pid | xargs kill
		rm monitor.pid
	else
		ps -ef|grep java|grep monitor-web|awk '{print $2}'|xargs kill
	fi
}

restart() {
	stop
	sleep 1
	start
}

usage() {
	cat <<EOF
	Usage: $PROGRAM {start | stop | restart | fstart}
EOF
}

case "X$1" in
	Xstart)
		start
		;;
	Xstop)
		stop
		;;
	Xrestart)
		restart
		;;
	Xfstart)
		fstart
		;;
	*)
		usage
		exit 1
esac

